﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace RzCorportativo.Views
{
    public partial class Idiomas : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                this.Nome.Attributes.Add("url", this.ResolveUrl("~/Views/Cadastros/Curriculo.aspx/ListarIdiomas"));
                var lista = Lib.IdiomaUsuario.Listar(new Lib.IdiomaUsuario()
                {
                    UsuarioId = (AppSession.Login.Usuario ?? new Lib.Usuario()).UsuarioId
                });
                foreach (var item in lista)
                {
                    var row = new System.Web.UI.HtmlControls.HtmlTableRow();
                    row.Cells.Add(new System.Web.UI.HtmlControls.HtmlTableCell()
                    {
                        InnerText = (item.Idioma ?? new Lib.Idioma()).Nome
                    });
                    row.Cells.Add(new System.Web.UI.HtmlControls.HtmlTableCell()
                    {
                        InnerText = "B".Equals(item.Nivel) ? "BÁSICO" : "I".Equals(item.Nivel) ? "INTERMEDIÁRIO" : "AVANÇADO"
                    });
                    row.Cells.Add(new System.Web.UI.HtmlControls.HtmlTableCell()
                    {
                        InnerHtml = "<input type='button' id='btnRemove" + item.IdiomaId.ToString() + 
                        "' onclick='RemoveItem(" + item.IdiomaId.ToString() + 
                        "," + (AppSession.Login.Usuario ?? new Lib.Usuario()).UsuarioId + 
                        ", this)' class='btn btn-danger' value='remover'/>"
                    });
                    row.Attributes.Add("idioma", item.IdiomaId.ToString());
                    this.gridIdiomas.Rows.Add(row);
                }
            }

        }

        public Lib.Idioma Model
        {
            get
            {
                Lib.Idioma idioma = new Lib.Idioma();
                idioma.Nome = Nome.Text;
                idioma.Nivel = Nivel.SelectedValue;

                return idioma;
            }
        }
    }
}